package com.aweqy.hrmanager.controller;

import com.aweqy.hrmanager.entity.CheckIn;
import com.aweqy.hrmanager.service.CheckInService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/check-ins")
@CrossOrigin(origins = "*")
public class CheckInController {

    @Autowired
    private CheckInService checkInService;

    @GetMapping
    public List<CheckIn> getAllCheckIns() {
        return checkInService.list();
    }

    @PostMapping
    public boolean addCheckIn(@RequestBody CheckIn checkIn) {
        try {
            System.out.println("接收到新增入住请求:");
            System.out.println("  checkInId: " + checkIn.getCheckInId());
            System.out.println("  customerId: " + checkIn.getCustomerId());
            System.out.println("  roomId: " + checkIn.getRoomId());
            System.out.println("  userId: " + checkIn.getUserId());
            System.out.println("  checkInDate: " + checkIn.getCheckInDate());
            System.out.println("  expectedCheckOutDate: " + checkIn.getExpectedCheckOutDate());
            System.out.println("  initialDeposit: " + checkIn.getInitialDeposit());
            System.out.println("  status: " + checkIn.getStatus());
            System.out.println("  notes: " + checkIn.getNotes());
            
            boolean result = checkInService.save(checkIn);
            System.out.println("新增入住结果: " + result);
            return result;
        } catch (Exception e) {
            System.err.println("新增入住失败: " + e.getMessage());
            e.printStackTrace();
            return false;
        }
    }

    @PutMapping
    public boolean updateCheckIn(@RequestBody CheckIn checkIn) {
        try {
            System.out.println("接收到修改入住请求: " + checkIn);
            boolean result = checkInService.updateById(checkIn);
            System.out.println("修改入住结果: " + result);
            return result;
        } catch (Exception e) {
            System.err.println("修改入住失败: " + e.getMessage());
            e.printStackTrace();
            return false;
        }
    }

    @DeleteMapping("/{id}")
    public boolean deleteCheckIn(@PathVariable Integer id) {
        try {
            System.out.println("接收到删除入住请求，ID: " + id);
            boolean result = checkInService.removeById(id);
            System.out.println("删除入住结果: " + result);
            return result;
        } catch (Exception e) {
            System.err.println("删除入住失败: " + e.getMessage());
            e.printStackTrace();
            return false;
        }
    }
} 